package com.jhhc.StormSurgeForecast.StormSurge.ServiceImpl;

import com.jhhc.StormSurgeForecast.StormSurge.Pojo.BDMS_ST_TIDE_E;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (BdmsStTideE)表服务实现类
 *
 * @author makejava
 * @since 2023-03-31 15:50:19
 */
@Service
public class BDMS_ST_TIDE_EServiceImpl implements com.jhhc.StormSurgeForecast.StormSurge.Service.BDMS_ST_TIDE_EService {
    @Resource
    private com.jhhc.StormSurgeForecast.AstronomicalTide.Dao.BDMS_ST_TIDE_EMapper BDMS_ST_TIDE_EMapper;

    @Value("${datasourceType}")
    String datasourceType;
    /**
     * 通过ID查询单条数据
     *
     * @param pid 主键
     * @return 实例对象
     */
    @Override
    public BDMS_ST_TIDE_E queryById(Integer pid) {
        return this.BDMS_ST_TIDE_EMapper.queryById(pid);
    }

    @Override
    public List<BDMS_ST_TIDE_E> queryAllByPid(Integer projectId, String stationCode, String startTime, String endTime) {
        return BDMS_ST_TIDE_EMapper.queryAllByPid(projectId, stationCode, startTime, endTime);
    }

    /**
     * 分页查询
     *
     * @param BDMS_ST_TIDE_E 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<BDMS_ST_TIDE_E> queryByPage(BDMS_ST_TIDE_E BDMS_ST_TIDE_E, PageRequest pageRequest) {
        long total = this.BDMS_ST_TIDE_EMapper.count(BDMS_ST_TIDE_E);
        return new PageImpl<>(this.BDMS_ST_TIDE_EMapper.queryAllByLimit(BDMS_ST_TIDE_E, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param BDMS_ST_TIDE_E 实例对象
     * @return 实例对象
     */
    @Override
    public BDMS_ST_TIDE_E insert(BDMS_ST_TIDE_E BDMS_ST_TIDE_E) {
        this.BDMS_ST_TIDE_EMapper.insert(BDMS_ST_TIDE_E);
        return BDMS_ST_TIDE_E;
    }

    @Override
    public int insertBatch(List<BDMS_ST_TIDE_E> entities) {

        if ("mysql".equals(datasourceType)){
            return   BDMS_ST_TIDE_EMapper.insertBatch(entities);
        }else if ("sqlserver".equals(datasourceType)){
            return BDMS_ST_TIDE_EMapper.insertBatchSqlserver(entities);
        }
        return  0;
    }



    /**
     * 通过主键删除数据
     *
     * @param pid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pid) {
        return this.BDMS_ST_TIDE_EMapper.deleteById(pid) > 0;
    }
}
